<?php
class ReplyAction extends CommonAction {
    public function index(){
	    parent::_list();
		$list=$this->list;
		foreach($list as $k => $v){
			if($v['MsgType'] == 'news'){
				$list[$k]['content'] = unserialize($v['content']);
			}
		}
		$this->assign('list', $list);
		$this->display();
	}
	
	//添加
	public function insert(){
		if($this->_post('MsgType') == 'news'){
			$data=array();
			$link=$this->_post('link');
			$img_url = $this->_post('img_url');
			$title = $this->_post('title');
			$description = $this->_post('description');
			foreach($title as $k => $v){
				$data[$k]['title'] = $title[$k];
				$data[$k]['img_url'] = $img_url[$k];
				$data[$k]['description'] = $description[$k];
				if(!(substr($link[$k],0,7) == 'http://' || substr($link[$k],0,8) == 'https://')){
			        $data[$k]['link'] = "__APP__".$link[$k];
		        }else{
					$data[$k]['link'] = $link[$k];
				}
				
			}
			$_POST['content'] = serialize($data);
		}
		if($this->_post('MsgType') == 'image'){
			$_POST['content'] = $_POST['img_url1'];
			$_POST['img_url'] = $_POST['img_url1'];
		}
		parent::insert();
	} 
	public function update(){
		if($this->_post('MsgType') == 'news'){
			$data=array();
			$link=$this->_post('link');
			$img_url = $this->_post('img_url');
			$title = $this->_post('title');
			$description = $this->_post('description');
			foreach($title as $k => $v){
				$data[$k]['title'] = $title[$k];
				$data[$k]['img_url'] = $img_url[$k];
				$data[$k]['description'] = $description[$k];
				if(!(substr($link[$k],0,7) == 'http://' || substr($link[$k],0,8) == 'https://')){
			        $data[$k]['link'] = "__APP__".$link[$k];
		        }else{
					$data[$k]['link'] = $link[$k];
				}
				
			}//dump($data);exit;
			$_POST['content'] = serialize($data);
		}
		
		if($this->_post('MsgType') == 'image'){
			$_POST['content'] = $_POST['img_url1'];
			$_POST['img_url'] = $_POST['img_url1'];
		}
		
		//dump($data);exit();
		parent::update();
	}
	
	//编辑
	public function edit(){
		if($this->_get('id')){
			$map['site_id'] = $this->siteid;
			$map['id'] = $this->_get('id');
			$info = $this->dao->where($map)->find();
			if($info['MsgType'] == 'news'){
				$newsList = unserialize($info['content']);
				$this->assign('newsList',$newsList );
				$info['content'] = '';
			}
			$this->assign('info',$info);
			$this->display();
		}
	}
}
?>